import {
  reqAddOrder,
  reqNameHospital,
  reqNameWheelchair,
  reqReturnOrder,
  reqReturnOrderStatus,
  reqUserOrderInfo
} from "../api";

const state = {
  hospitalNameInfo:{},
  wheelchairInfo:[],
  userOrder:[],
  addOrderCode:{}
}
const mutations = {
  GETHOSPITALNAME(state,result){
    state.hospitalNameInfo = result
  },
  GETWHEELCHAIRINFO(state,data){
    state.wheelchairInfo = data
  },
  GETUSERORDERS(state,data){
    state.userOrder = data
  },
  ADDORDER(state,result){
    state.addOrderCode = result
  }
}

const actions = {
  //通过名字获取医院信息
  async getNameHospital({commit},{name}){
    let result = await reqNameHospital({name})
    if (result){
      commit('GETHOSPITALNAME',result)
    }
  },
  //通过医院名字获取轮椅信息
  async getNameWheelchair({commit},{hospitalName}){
    let result = await reqNameWheelchair({hospitalName})
    if (result){
      commit('GETWHEELCHAIRINFO',result.data)
    }
  },
  async getUserOrders({commit},{userId}){
    let result = await reqUserOrderInfo({userId})
    if (result.code === 1){
      commit('GETUSERORDERS',result.data)
    }
  },
  //下单
  async addUserOrder({commit},data){
    let result = await reqAddOrder(data)
    if (result.code === 1){
      commit('ADDORDER',result)
    }
  },
  //修改订单状态
  async returnStatus({commit},data){
    await reqReturnOrderStatus(data)
  },
}

const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}
